<template>
  <div class="add_con_form tl" v-loading="loading">
    <el-dialog :close-on-click-modal="false" title="编辑收款信息" :modal-append-to-body="false" :visible.sync="visible" :show="show"
        :before-close="closeDialog" @close="$emit('update:show', false)" class="tl size_13" width="800px">
      <el-form :model="data" :rules="dataYZ" ref="data" class="mar_top" label-width="120px">
        <div v-if="nowsel == 'zfb'">
          <el-form-item label="支付宝" prop="alipay">
            <el-col :span="12">
              <el-input placeholder="" v-model="data.alipay" clearable>
              </el-input>
            </el-col>
          </el-form-item>

          <el-form-item label="支付宝姓名" prop="alipay_name">
            <el-col :span="12">
              <el-input placeholder="" v-model="data.alipay_name" clearable>
              </el-input>
            </el-col>
          </el-form-item>

          <el-form-item label="支付宝二维码" prop="avatar">
            <el-col :span="12">
              <el-input v-model="data.alipay_pic" autocomplete="off" class="mar_bottom_5"></el-input>

              <uploadpic :piclink="data.alipay_pic" :width="150" :height="150" :is_more="false" @send_pic="onSuccess"></uploadpic>
            </el-col>
          </el-form-item>
        </div>
        <div v-else-if="nowsel == 'wx'">
          <el-form-item label="微信号" prop="wechat">
            <el-col :span="12">
              <el-input placeholder="" v-model="data.wechat" clearable>
              </el-input>
            </el-col>
          </el-form-item>

          <el-form-item label="微信二维码" prop="avatar">
            <el-col :span="12">
              <el-input v-model="data.wechat_pic" autocomplete="off" class="mar_bottom_5"></el-input>
              <uploadpic :piclink="data.wechat_pic" :width="150" :height="150" :is_more="false" @send_pic="onSuccess1"></uploadpic>
            </el-col>
          </el-form-item>
        </div>
        <div v-else-if="nowsel == 'bank'">
          <el-form-item label="银行账户" prop="bank_card">
            <el-col :span="12">
              <el-input placeholder="" v-model="data.bank_card" clearable>
              </el-input>
            </el-col>
          </el-form-item>

          <el-form-item label="开户名" prop="bank_name">
            <el-col :span="12">
              <el-input placeholder="" v-model="data.bank_name" clearable>
              </el-input>
            </el-col>
          </el-form-item>

          <el-form-item label="开户行" prop="bank">
            <el-col :span="12">
              <el-select v-model="data.bank" placeholder="请选择">
                <el-option v-for="item in banks" :key="item" :label="item" :value="item"></el-option>
              </el-select>
            </el-col>
          </el-form-item>
          <el-form-item label="开户省市" prop="bank_province">
            <el-col :span="12">
              <city-cascader :level="1" :placeholder="
                  data.bank_province
                    ? data.bank_province + ' - ' + data.bank_city
                    : ''
                " @change="Rolechanges" />
            </el-col>
          </el-form-item>

          <el-form-item label="开户网点" prop="bank_network">
            <el-col :span="12">
              <el-input placeholder="" v-model="data.bank_network" clearable>
              </el-input>
            </el-col>
          </el-form-item>
        </div>

        <div class="mar_bottom_15">
          <span class="sizeColor size_13 sp_style"></span>
          <el-button :loading="$store.state.isLoading" size="medium" type="primary" @click.prevent="addUpdate('data')">确定</el-button>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>

<style lang="less" scoped></style>

<script>
import banks from "../../assets/js/banks";
import compressimgUpload from "@/components/currency/compressimgUpload.vue";
import cityCascader from "@/components/currency/cityCascader/cityCascader";
import uploadpic from "@/components/page/pic/up_pic";
export default {
  components: {
    compressimgUpload,
    cityCascader,
    uploadpic
  },
  data () {
    var checkTitle = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("标题不能为空"));
      } else {
        callback();
      }
    };

    return {
      value: "",
      banks: banks,
      fileList: [],
      data: {
        uid: "",
        alipay: "",
        alipay_name: "",
        wechat: "",
        bank_card: "",
        bank_name: "",
        bank: "",
        bank_network: "",
        bank_province: "",
        bank_city: "",
        alipay_pic: "",
        wechat_pic: ""
      },
      loading: false,
      options: this.$addressJson,
      optionsitem: [],
      dataYZ: {
        alipay: [
          { required: true, message: "请输入支付宝账号", trigger: "blur" }
        ],
        alipay_name: [
          { required: true, message: "请输入支付宝姓名", trigger: "blur" },
          { min: 2, max: 6, message: "长度在 2 到6 个字符", trigger: "blur" }
        ],
        wechat: [
          { required: true, message: "请输入微信账号", trigger: "blur" }
        ],
        bank_card: [
          { required: true, message: "请输入银行卡账号", trigger: "blur" },
          { min: 12, message: "银行卡最低12位", trigger: "blur" }
        ],
        bank_name: [
          { required: true, message: "请输入银行卡账号", trigger: "blur" },
          { min: 2, max: 6, message: "长度在 2 到6 个字符", trigger: "blur" }
        ],
        bank: [{ required: true, message: "请选择开户行", trigger: "change" }],
        bank_province: [
          { required: true, message: "请选择开户省", trigger: "change" }
        ]
      },
      visible: this.show
    };
  },
  props: {
    show: Boolean,
    editId: String,
    clickNum: Number,
    nowsel: String
  },
  methods: {
    onSuccess (src) {
      this.data.alipay_pic = src;
    },
    onSuccess1 (src) {
      this.data.wechat_pic = src;
    },
    Rolechanges (val) {
      this.data.bank_province = val[0];
      this.data.bank_city = val[1];
    },
    closeDialog () {
      this.visible = false;
    },
    getDetails (id) {
      var data = {};
      data["id"] = id;
      this.$api.getUser.collectionsEdit(data).then(res => {
        console.log(res);
        if (res.data.code == 200 && res.data.result != null) {
          this.data = res.data.result;
        }
      });
      console.log(typeof data); //object
      // {id: 1, sign: "ca3ca63b05dafe8fe3ab8c719055b44c"}
    },
    addUpdate (formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          var params = {};
          params["id"] = this.data.uid;
          params["alipay"] = this.data.alipay;
          params["alipay_name"] = this.data.alipay_name;
          params["wechat"] = this.data.wechat;
          params["bank_card"] = this.data.bank_card;
          params["bank_name"] = this.data.bank_name;
          params["bank"] = this.data.bank;
          params["bank_network"] = this.data.bank_network;
          params["bank_province"] = this.data.bank_province;
          params["bank_city"] = this.data.bank_city;
          params["alipay_pic"] = this.data.alipay_pic;
          params["wechat_pic"] = this.data.wechat_pic;

          this.$api.getUser.collectionsSaveEdit(params).then(res => {
            console.log(res);
            if (res.data.code == 200 && res.data.result != null) {
              this.$emit("parent", "这里刷新父页面");
              this.$fnc.alertSuccess({ text: "编辑成功" }); //成功弹出框
              this.visible = false;
            } else {
              this.$fnc.alertError(res.data.result); //失败弹出框
            }
          });
        }
      });
    }
  },
  watch: {
    show () {
      console.log(this.show);
      this.visible = this.show;
    },
    clickNum (id) {
      console.log("点击button次数", id);
      console.log("编辑ID=" + this.editId);
      this.getDetails(this.editId);
    }
  },
  mounted () {
    //this.getDetails(this.$route.query.id);
  },
  created () { }
};
</script>
